import map from '@/components/network/map'
import { getMapData } from '@/api/mock/index'
export const FLOOR_DATA ={
    "F1": null,
    "F2": null,
    "F3": null,
    "F4": null
}

export const FLOOR_ENDPOINTS = {// 替换为实际接口地址
    base: 'http://127.0.0.1:5088/api/floor_data'
};
async function fetchFloorData(floor) {
    try {
        // 直接调用接口定义
        const data = await getMapData(floor);
        return data;
    } catch (error) {
        console.error(`数据获取失败:`, error);
        return null;
    }
}

export async function loadFloorData(floor) {
    if (!['F1', 'F2', 'F3', 'F4'].includes(floor)) {
        throw new Error(`无效的楼层标识: ${floor}`);
    }

    if (FLOOR_DATA[floor]) return FLOOR_DATA[floor];

    const data = await fetchFloorData(floor);
    if (data) {
        FLOOR_DATA[floor] = data;
    }
    console.log('数据加载成功:',  FLOOR_DATA[floor])
    return data;
}

// 批量加载所有楼层数据
export async function loadAllFloors() {
    const floors = ['F1', 'F2', 'F3', 'F4'];
    const loadPromises = floors.map(floor => loadFloorData(floor));
    return Promise.all(loadPromises);
}
